<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Project
 *
 * @author Zoila
 */
class Project  extends AppModel{
    //put your code here
    
    public $validate = array(
        'name' => array(
            'rule' => 'notEmpty'
        )
    );
    
    public $hasMany = array(
        'Story' => array(
            'className'  => 'Story',
            'foreignKey' => 'project_id',
            'order'      => 'Story.created DESC'
        )
    );
    
    
    public $hasAndBelongsToMany = array(
        'Team' =>
            array(
                'className'              => 'Team',
                'joinTable'              => 'project_teams',
                'foreignKey'             => 'project_id',
                'associationForeignKey'  => 'team_id',
                'unique'                 => true,
                'conditions'             => '',
                'fields'                 => '',
                'order'                  => '',
                'limit'                  => '',
                'offset'                 => '',
                'finderQuery'            => '',
                'deleteQuery'            => '',
                'insertQuery'            => ''
            )
    );
    
    public function isOwnedBy($project, $user) {
        return $this->field('id', array('id' => $project, 'creator_id' => $user)) === $project;
    }
}

?>
